package com.gin.no_gay_alliance.utils;

import static android.view.View.GONE;
import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;

import android.view.View;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.gin.no_gay_alliance.annotation.Visibility;

/**
 * view工具类
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/8/26 10:55
 **/
public class ViewUtils {

    /**
     * 批量设置选中状态的切换回调
     *
     * @param onCheckedChangeListener 回调
     * @param compoundButtons         开关/复选框等
     */
    public static void setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener onCheckedChangeListener, CompoundButton... compoundButtons) {
        if (compoundButtons == null) {
            return;
        }
        for (CompoundButton button : compoundButtons) {
            button.setOnCheckedChangeListener(onCheckedChangeListener);
        }
    }

    /**
     * 批量设置view的显示状态
     *
     * @param visibility 显示状态
     * @param views      views
     */
    public static void setVisibility(@Visibility int visibility, View... views) {
        if (views == null) {
            return;
        }
        for (View view : views) {
            view.setVisibility(visibility);
        }
    }

    /**
     * 如果满足条件,设置view的显示状态到GONE, 否则设置为 VISIBLE
     *
     * @param condition 条件
     * @param views     views
     */
    public static void setGone(boolean condition, View... views) {
        setVisibility(condition ? GONE : VISIBLE, views);
    }

    /**
     * 如果满足条件,设置view的显示状态到INVISIBLE, 否则设置为 VISIBLE
     *
     * @param condition 条件
     * @param views     views
     */
    public static void setInvisible(boolean condition, View... views) {
        setVisibility(condition ? INVISIBLE : VISIBLE, views);
    }

    /**
     * 设置view的可用状态
     *
     * @param enabled   是否可用
     * @param textViews views
     */
    public static void setEnable(boolean enabled, TextView... textViews) {
        if (textViews == null) {
            return;
        }
        for (TextView tv : textViews) {
            tv.setEnabled(enabled);
        }
    }

    /**
     * 设置点击监听
     *
     * @param listener listener
     * @param views    views
     */
    public static void setOnClickListener(View.OnClickListener listener, View... views) {
        if (views != null) {
            for (View view : views) {
                view.setOnClickListener(listener);
            }
        }
    }

    /**
     * 设置tag
     *
     * @param tag   tag
     * @param views views
     */
    public static void setTag(Object tag, View... views) {
        if (views != null) {
            for (View view : views) {
                view.setTag(tag);
            }
        }
    }

}
